/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.iecg.controller.app;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.iecg.api.entity.IecgUserEmergency;
import com.iecg.filter.RequestHolder;
import com.iecg.service.IecgUserEmergencyService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 用户紧急联系
 *
 * @author pigx code generator
 * @date 2019-10-16 09:58:43
 */
@RestController
@AllArgsConstructor
@RequestMapping("app/useremergency" )
@Api(value = "app_iecguseremergency", tags = "App用户紧急联系管理")
public class AppUserEmergencyController {

    private final IecgUserEmergencyService iecgUserEmergencyService;

    /**
     * 通过userId查询用户紧急联系
     * @param userName userName
     * @return R
     */
    @ApiOperation(value = "通过userName查询", notes = "通过userName查询")
    @GetMapping("/{userName}" )
    public R getById(@PathVariable("userName" ) String userName) {
        return R.ok(iecgUserEmergencyService.list(Wrappers.<IecgUserEmergency>query()
				.lambda().eq(IecgUserEmergency::getUserName, userName)));
    }

    /**
     * 新增用户紧急联系
     * @param iecgUserEmergency 用户紧急联系
     * @return R
     */
    @ApiOperation(value = "新增用户紧急联系", notes = "新增用户紧急联系")
    @SysLog("新增用户紧急联系" )
    @PostMapping
    public R save(@RequestBody IecgUserEmergency iecgUserEmergency) {
		if(RequestHolder.getParam()== null){
			return R.failed("未验证手机验证码");
		}
        return R.ok(iecgUserEmergencyService.save(iecgUserEmergency));
    }

    /**
     * 修改用户紧急联系
     * @param iecgUserEmergency 用户紧急联系
     * @return R
     */
    @ApiOperation(value = "修改用户紧急联系", notes = "修改用户紧急联系")
    @SysLog("修改用户紧急联系" )
    @PutMapping
    public R updateById(@RequestBody IecgUserEmergency iecgUserEmergency) {
        return R.ok(iecgUserEmergencyService.updateById(iecgUserEmergency));
    }

    /**
     * 通过id删除用户紧急联系
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除用户紧急联系", notes = "通过id删除用户紧急联系")
    @SysLog("通过id删除用户紧急联系" )
    @DeleteMapping("/{id}" )
    public R removeById(@PathVariable Long id) {
        return R.ok(iecgUserEmergencyService.removeById(id));
    }

}
